package com.zj.aop;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;


public class MyAdvice {


    public void myBefore(JoinPoint joinPoint) {
        System.out.println("前置通知" + joinPoint.getSignature());
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            System.out.println("参数：" + arg);
        }

    }

    public void myAfter(int a, int b) {
        System.out.println(a + " ," + b);
        System.out.println("后置通知");
    }

    public void myThrow(JoinPoint joinPoint, Exception ex) {
        System.out.println(joinPoint.getSignature() + "异常通知：" + ex.getMessage());
    }

    public Object myAround(ProceedingJoinPoint pp) {
        Object[] args = pp.getArgs();
        Object obj = null;
        System.out.println("环绕通知前,args.size:" + args.length);
        for (Object arg : args) {
            System.out.println("参数：" + arg);
        }
        try {
            obj = pp.proceed();
            System.out.println("环绕通知后,返回值:" + obj);

        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return obj;

    }
}
